package com.zige.zige.dialog;

import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.zige.zige.R;

/**
 * Created by Fei on 2015/12/15.
 */
public class PromptDialog extends DialogFragment {

    private View view;
    private TextView tv_prompt_title,tv_prompt_content;
    private Button btn_ok;
    private DialogLister dialogLister = null;
    private String contentString = null;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        view = inflater.inflate(R.layout.dialog_prompt, container);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        Window window = getDialog().getWindow();

        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setAttributes(lp);
        getDialog().show();
        getDialog().setCanceledOnTouchOutside(true);
        getDialog().setCancelable(false);

        initView();
        setContext();
        return  view;

    }

    private void initView(){
        btn_ok = (Button)view.findViewById(R.id.btn_ok_cf);
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDialog().dismiss();
                if (dialogLister != null) {
                    dialogLister.clickTrue();
                }
            }
        });
    }

    public void setContext(){
        tv_prompt_content = (TextView)view.findViewById(R.id.tv_prompt_content);
        if (!TextUtils.isEmpty(contentString)) {
            tv_prompt_content.setText(contentString);
        } else {
            tv_prompt_content.setText("请登录之后在进行点赞吧");
        }
    }

    public void setContextString(String string) {
        if (!TextUtils.isEmpty(string)) {
            contentString = string;
        }
    }

    public interface DialogLister {
        void clickTrue();
    }

    public void setDialogLister(DialogLister dialogLister) {
        this.dialogLister = dialogLister;
    }
}
